package com.twu.solo;

import java.io.*;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: thoughtworker
 * Date: 10/10/13
 * Time: 1:16 PM
 * To change this template use File | Settings | File Templates.
 */
public class FootballLeagueManagerApp {
    private Menu mainMenu;
    private BufferedReader reader;
    private Map<String, Command> commandMap;

    public FootballLeagueManagerApp(Menu mainMenu, BufferedReader reader, Map<String, Command> commandMap) {
        this.mainMenu = mainMenu;
        this.reader = reader;
        this.commandMap = commandMap;
    }


    public void runApplication() throws IOException {
            mainMenu.printMenuOptions();
            respondToMenuUserInput();
    }


    public void respondToMenuUserInput() throws IOException {
        String userInput = reader.readLine();
        if(commandMap.get(userInput) != null) {
            commandMap.get(userInput).execute();
        } else {
            commandMap.get("invalid").execute();
        }
    }


}
